package com.xzy.urp.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xzy.urp.pojo.entity.CourseTime;
import com.xzy.urp.mapper.CourseTimeMapper;
import com.xzy.urp.pojo.vo.CourseTimeVO;
import com.xzy.urp.service.CourseTimeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xzy
 * @since 2022-02-17
 */
@Service
public class CourseTimeServiceImpl extends ServiceImpl<CourseTimeMapper, CourseTime> implements CourseTimeService {


    @Override
    public List<CourseTimeVO> getByTeacherId(Long tId, Integer semester) {
       return baseMapper.getByTeacherId(tId,semester);
    }

    @Override
    public List<CourseTimeVO> getByStudentId(Long sId, Integer semester) {
        return baseMapper.getByStudentId(sId,semester);
    }

    @Override
    public void removeCtime(Long cId) {
        baseMapper.delete(new QueryWrapper<CourseTime>().eq("course_id", cId));

    }

    @Override
    public void addCtime(CourseTimeVO courseTimeVO) {
        CourseTime courseTime = new CourseTime();
        BeanUtil.copyProperties(courseTimeVO,courseTime);
        baseMapper.insert(courseTime);

    }

    @Override
    public Boolean isPlan(Long tId, Integer start, Integer end) {
        Integer count = baseMapper.countByWeek(tId, start, end);
        //等于0表示没有周期内没有课程（可置入）
        return count == 0;
    }
}
